#include <stdio.h>
#define abs(a) ((a) > 0 ? (a) : -(a))
int main() {
  for (int i = 1; i <= 5; i++)
    for (int j = 1; j <= 5; j++) {
      int a;
      scanf("%d", &a);
      if (a == 1) {
        printf("%d\n", abs(i - 3) + abs(j - 3));
        return 0;
      }
    }
}